<?php

class GalactusModelGallery extends GalactusModelPost {

	function __construct($control) {
		parent::__construct($control);
	}

	public function addContent($file, $file_type, $ra, $dec, $az, $alt, $title = NULL, $text = NULL) {
		$sql = "
			INSERT INTO Content(user_id, file, file_type, right_ascension, declination, azimuth, altitude, created_on, title, text)
			VALUES (:user_id, :file, :file_type, :right_ascension, :declination, :azimuth, :altitude, NOW( ), :title, :text)
		";
		$params = array(
			":user_id" => $this->control->user_id,
			":file" => $file,
			":file_type" => $file_type,
			":right_ascension" => $ra,
			":declination" => $dec,
			":azimuth" => $az,
			":altitude" => $alt,
			":title" => $title,
			":text" => $text
		);
		$this->query($sql, $params);
	}

	public function removeContent($content_id) {
		$query = $this->query(
			"DELETE FROM Content WHERE id = :content_id",
			array(":content_id" => $content_id)
		);
		if(!$query["fail"])
			echo $this->control->view->helper->alertSuccess("Conteúdo removido com sucesso!", URL."REDIRECT/USER/SHOW");
		else throw new Exception("Falha na remoção do conteúdo!");
	}

	public function retrieveContent($content_id = NULL, $user_id = NULL) {
		$sql = "";
		$params = NULL;
		if(!empty($content_id) || !empty($user_id)) {
			$sql = "WHERE ";
			if(!empty($content_id)) {
				$sql .= "id = :telescope_id ";
				$params[":content_id"] = $content_id;
				if(!empty($user_id)) {
					$sql .= "AND user_id = :user_id";
					$params[":user_id"] = $user_id;
				}
			}
			if(empty($content_id) && !empty($user_id)) {
				$sql .= "user_id = :user_id";
				$params[":user_id"] = $user_id;
			}
		}
		$sql = "SELECT * FROM Content ".$sql." ORDER BY created_on DESC";
		$query = $this->query($sql, $params);
		if(!$query["fail"])
			return $query["result"];
		else return NULL;
	}






}

?>
